<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-datatable table {
                border-collapse: collapse;
                width: 100%;
                border-color: grey;
            }
            .ui-datatable .ui-datatable-header, .ui-datatable .ui-datatable-footer {
                text-align: center;
                padding: 4px 10px 4px 160px;
            }
            .ui-inputfield, .ui-widget-content .ui-inputfield, .ui-widget-header .ui-inputfield {
                width: 60px;
            }
        </style>
        <h:form id="sfInfoForm">
            <p:panel header="Sales Forecast Basic Information">
                <p:messages showDetail="true"/>
                <h:panelGrid columns="4">
                    <h:outputLabel style="font-weight: bold" value="Date Created: "/>
                    <h:outputText value="#{sfEditManagerBean.selectedSF.getFormattedDay()}"/>
                    <h:outputText value=""/>
                    <h:outputText value=""/>

                    <h:outputLabel style="font-weight: bold" value="Personal: "/>
                    <h:outputLabel value="#{sfEditManagerBean.selectedSF.staff.fullName}"/>
                    <h:outputText value=""/>
                    <h:outputText value=""/>

                    <h:outputLabel style="font-weight: bold" value="Period to forecast: "/>
                    <h:outputText value="#{sfEditManagerBean.selectedSF.getForecastedPeriod()}"/>
                    <h:outputText value=""/>
                    <h:outputText value=""/>
                </h:panelGrid>
                <p:commandButton value="Update and Save" ajax="false" action="#{sfEditManagerBean.confirmEdit}"/>
                <p:ajaxStatus style="width: 16px;height: 16px;">
                    <f:facet name="start">
                        <h:graphicImage value="./../images/ajaxloading.gif"/>
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value=""/>
                    </f:facet>
                </p:ajaxStatus>
            </p:panel>
        </h:form>
        <br/>
        <br/>
        <p:tabView cache="true" dynamic="true">
            <p:tab title="Product Sales Forecast">
                <h:form id="allProductBPForm">
                    <p:messages showDetail="true"/>
                    <p:panel header="Options">
                        <p:commandButton value="Calculate All" ajax="true" update="allProductBPForm" actionListener="#{sfEditManagerBean.calculateAll}"/>
                        <p:commandButton value="Input Industry Index" ajax="true" onclick="industryInfoDlg.show()"/>
                    </p:panel>
                    <c:forEach items="#{sfEditManagerBean.counterForProduct}" var="count">
                        <div style="border:1px solid gray;width:700px;overflow-y:hidden;overflow-x:scroll;">
                            <div class="ui-datatable ui-widget">
                                <table border="1" summary="for product a">
                                    <caption>
                                        <div class="ui-datatable-header ui-widget-header ui-corner-tl ui-corner-tr">
                                            Sales Forecast for Product <h:outputText value="#{sfEditManagerBean.returnProductName(count)}"/>
                                        </div>
                                    </caption>

                                    <thead>
                                        <tr>
                                            <th class="ui-state-default" colspan="3" rowspan="2"></th>
                                            <th class="ui-state-default" colspan="6">Month</th>
                                            <th class="ui-state-default" rowspan="2">Options</th>
                                        </tr>

                                        <tr>
                                            <c:forEach items="#{sfEditManagerBean.labels}" var="lab">
                                                <th class="ui-state-default"><h:outputText value="#{lab}"/></th>
                                            </c:forEach>
                                        </tr>
                                    </thead>

                                    <tbody class="ui-datatable-data">
                                        <tr>
                                            <th class="ui-state-default" rowspan="4">Base Projection</th>
                                            <th class="ui-state-default" colspan="2">Historical</th>
                                            <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                                <td><h:outputText value="#{sfEditManagerBean.roundToLong((1+sfEditManagerBean.selectedSF.returnProductIndivForecast(count).historicalSF.yoy)*(sfEditManagerBean.previousTotalSales.get(count).get(item)-sfEditManagerBean.previousPromotion.get(count).get(item)))}"/></td>
                                            </c:forEach>
                                            <td><p:commandButton image="ui-icon ui-icon-pencil" ajax="true" update="historicalForm" onclick="historicalDlg.show()" action="#{sfEditManagerBean.selectHistoricalSF(count)}"/></td>
                                        </tr>

                                        <tr>
                                            <th class="ui-state-default" colspan="2">Industry</th>
                                            <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                                <td><h:outputText value="#{sfEditManagerBean.roundToLong(sfEditManagerBean.selectedSF.returnProductIndivForecast(count).industrySF.proudctShare*sfEditManagerBean.selectedSF.returnProductIndivForecast(count).industrySF.marketShare*(1+sfEditManagerBean.selectedSF.returnProductIndivForecast(count).industrySF.yoy)*sfEditManagerBean.prevIndustryTotDmd.get(item))}"/></td>
                                            </c:forEach>
                                            <td><p:commandButton ajax="true" image="ui-icon ui-icon-search" update="industryForm" onclick="industryDlg.show()" action="#{sfEditManagerBean.selectIndustrySF(count)}"/></td>
                                        </tr>

                                        <tr>
                                            <th class="ui-state-default" colspan="2">Static</th>
                                            <c:forEach items="#{sfEditManagerBean.staticPeriods}" var="item">
                                                <td><h:outputText value="#{sfEditManagerBean.roundToLong((sfEditManagerBean.trend.get(count) * item + sfEditManagerBean.level.get(count))* sfEditManagerBean.returnEstimDesFactorByProductNPeriod(item, count))}" /></td>
                                            </c:forEach>
                                            <td><p:commandButton ajax="true" image="ui-icon ui-icon-pencil" update="staticForm" onclick="staticDlg.show()" action="#{sfEditManagerBean.selectStaticSF(count)}"/></td>
                                        </tr>

                                        <tr>
                                            <th class="ui-state-default">Select</th>
                                            <th>
                                                <h:selectOneMenu value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(count).createdType}"
                                                                 required="true" requiredMessage="Please select one">
                                                    <f:selectItems value="#{sfEditManagerBean.completeCreatedMethod()}" var="item" itemLabel="#{item}" itemValue="#{item}"/>
                                                </h:selectOneMenu>
                                            </th>
                                            <c:forEach items="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(count).baseProjectionSelected}" var="item">
                                                <td><h:outputText value="#{item.longValue}"/></td>
                                            </c:forEach>
                                            <td><p:commandButton ajax="true" image="ui-icon ui-icon-refresh" update="allProductBPForm" action="#{sfEditManagerBean.updateBPNCalculateFinal(count)}"/></td>
                                        </tr>

                                        <tr>
                                            <th class="ui-state-default" colspan="3">Promotion</th>
                                            <c:forEach items="#{sfEditManagerBean.promotions.get(count)}" var="item">
                                                <td><p:inputText value="#{item.l}"
                                                                 required="true" requiredMessage="Please filling in the forecasted promotion."/></td>
                                            </c:forEach>
                                            <td><p:commandButton ajax="true" image="ui-icon ui-icon-refresh" update="allProductBPForm" action="#{sfEditManagerBean.updateBPNCalculateFinal(count)}"/></td>
                                        </tr>

                                        <tr>
                                            <th class="ui-state-default" colspan="3">Manual Adjustment</th>
                                            <c:forEach items="#{sfEditManagerBean.humanAdjusts.get(count)}" var="item">
                                                <td><p:inputText value="#{item.l}"
                                                                 required="true" requiredMessage="Manual Adjustment should not be empty."/></td>
                                            </c:forEach>
                                            <td><p:commandButton ajax="true" image="ui-icon ui-icon-refresh" update="allProductBPForm" action="#{sfEditManagerBean.updateBPNCalculateFinal(count)}"/></td>
                                        </tr>

                                        <tr>
                                            <th class="ui-state-default" colspan="3">Final</th>
                                            <c:forEach items="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(count).finalValues}" var="item">
                                                <td><h:outputText value="#{item.longValue}"/></td>
                                            </c:forEach>
                                            <td><p:commandButton ajax="true" image="ui-icon ui-icon-refresh" update="allProductBPForm" action="#{sfEditManagerBean.updateBPNCalculateFinal(count)}"/></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <br/>
                        <br/>
                    </c:forEach>
                </h:form>
                <p:dialog id="historicalDialog" widgetVar="historicalDlg" header="Update Sales Forecast based on Historical Data" showEffect="explode" hideEffect="explode"
                          width="780" height="250">
                    <h:form id="historicalForm">
                        <p:messages id="hisMsg" showDetail="true"/>
                        <div class="ui-datatable ui-widget">
                            <table border="1" summary="for product a">
                                <caption>
                                    <div class="ui-datatable-header ui-widget-header ui-corner-tl ui-corner-tr">
                                        Sales Forecast for Product <h:outputText value="#{sfEditManagerBean.returnProductName(sfEditManagerBean.selectedHistoricalId)}"/>
                                    </div>
                                </caption>

                                <thead>
                                    <tr>
                                        <th class="ui-state-default" colspan="3" rowspan="2"></th>
                                        <th class="ui-state-default" colspan="6">Month</th>
                                    </tr>

                                    <tr>
                                        <c:forEach items="#{sfEditManagerBean.labels}" var="lab">
                                            <th class="ui-state-default"><h:outputText value="#{lab}"/></th>
                                        </c:forEach>
                                    </tr>
                                </thead>

                                <tbody class="ui-datatable-data">
                                    <!--                        historical part-->
                                    <tr>
                                        <th class="ui-state-default" rowspan="5">Historical</th>
                                        <th class="ui-state-default" rowspan="3">Previous</th>
                                        <th class="ui-state-default">Total Sales(Bases)</th>
                                        <c:forEach items="#{sfEditManagerBean.previousTotalSales.get(sfEditManagerBean.selectedHistoricalId)}" var="item" varStatus="forLoop">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Promotion Sales</th>
                                        <c:forEach items="#{sfEditManagerBean.previousPromotion.get(sfEditManagerBean.selectedHistoricalId)}" var="item" varStatus="forLoop">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Base Sales</th>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.previousTotalSales.get(sfEditManagerBean.selectedHistoricalId).get(item)-sfEditManagerBean.previousPromotion.get(sfEditManagerBean.selectedHistoricalId).get(item)}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Growth</th>
                                        <th>
                                            <p:inputText value="#{sfEditManagerBean.histYoYs.get(sfEditManagerBean.selectedHistoricalId).yoy}"
                                                         required="true" requiredMessage="Growth rate shouldn't be empty."/>
                                        </th>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong(sfEditManagerBean.histYoYs.get(sfEditManagerBean.selectedHistoricalId).yoy*(sfEditManagerBean.previousTotalSales.get(sfEditManagerBean.selectedHistoricalId).get(item)-sfEditManagerBean.previousPromotion.get(sfEditManagerBean.selectedHistoricalId).get(item)))}"/></td> 
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Current</th>
                                        <th class="ui-state-default">Base Projection Cases</th>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong((1+sfEditManagerBean.histYoYs.get(sfEditManagerBean.selectedHistoricalId).yoy)*(sfEditManagerBean.previousTotalSales.get(sfEditManagerBean.selectedHistoricalId).get(item)-sfEditManagerBean.previousPromotion.get(sfEditManagerBean.selectedHistoricalId).get(item)))}"/></td>
                                        </c:forEach>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <p:commandButton value="Calculate" ajax="true" update="allProductBPForm, historicalForm, hisMsg" action="#{sfEditManagerBean.calculateHistorical(sfEditManagerBean.selectedHistoricalId)}"/>
                        <p:commandButton value="Update" update="allProductBPForm, historicalForm" oncomplete="historicalDlg.hide()" action="#{sfEditManagerBean.confirmHistorical(sfEditManagerBean.selectedHistoricalId)}"/>
                    </h:form>
                </p:dialog>
                <p:dialog id="industryDialog" widgetVar="industryDlg" header="View Industry Data" showEffect="explode" hideEffect="explode"
                          width="780" height="220">
                    <h:form id="industryForm">
                        <p:messages showDetail="true"/>
                        <div class="ui-datatable ui-widget">
                            <table border="1" summary="for product a">
                                <caption>
                                    <div class="ui-datatable-header ui-widget-header ui-corner-tl ui-corner-tr">
                                        Sales Forecast for Product <h:outputText value="#{sfEditManagerBean.returnProductName(sfEditManagerBean.selectedHistoricalId)}"/>
                                    </div>
                                </caption>

                                <thead>
                                    <tr>
                                        <th class="ui-state-default" colspan="3" rowspan="2"></th>
                                        <th class="ui-state-default" colspan="6">Month</th>
                                    </tr>

                                    <tr>
                                        <c:forEach items="#{sfEditManagerBean.labels}" var="lab">
                                            <th class="ui-state-default"><h:outputText value="#{lab}"/></th>
                                        </c:forEach>
                                    </tr>
                                </thead>

                                <tbody class="ui-datatable-data">
                                    <!--                        industry part-->
                                    <tr>
                                        <th class="ui-state-default" rowspan="6">Industry</th>
                                        <th class="ui-state-default" colspan="2">Previous Year Demand</th>
                                        <c:forEach items="#{sfEditManagerBean.prevIndustryTotDmd}" var="item">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Growth</th>
                                        <td>
                                            <h:outputText value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.yoy}"/>
                                        </td>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong(sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.yoy*sfEditManagerBean.prevIndustryTotDmd.get(item))}" /></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Forecasted Demand</th>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong((1+sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.yoy)*sfEditManagerBean.prevIndustryTotDmd.get(item))}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Market Share</th>
                                        <td>
                                            <h:outputText value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.marketShare}"/>
                                        </td>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong(sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.marketShare*(1+sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.yoy)*sfEditManagerBean.prevIndustryTotDmd.get(item))}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Product Share</th>
                                        <td>
                                            <h:outputText value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.proudctShare}"/>
                                        </td>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong(sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.proudctShare*sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.marketShare*(1+sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.yoy)*sfEditManagerBean.prevIndustryTotDmd.get(item))}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Base Projection</th>
                                        <c:forEach items="#{sfEditManagerBean.counter}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong(sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.proudctShare*sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.marketShare*(1+sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedIndustryId).industrySF.yoy)*sfEditManagerBean.prevIndustryTotDmd.get(item))}"/></td>
                                        </c:forEach>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </h:form>
                </p:dialog>
                <p:dialog id="staticDialog" widgetVar="staticDlg" header="View Static Data" showEffect="explode" hideEffect="explode"
                          width="780">
                    <h:form id="staticForm">
                        <p:messages id="staticMsg" showDetail="true"/>
                        <div class="ui-datatable ui-widget">
                            <table border="1" summary="for product a">
                                <caption>
                                    <div class="ui-datatable-header ui-widget-header ui-corner-tl ui-corner-tr">
                                        Sales Forecast for Product <h:outputText value="#{sfEditManagerBean.returnProductName(sfEditManagerBean.selectedStaticId)}"/>
                                    </div>
                                </caption>

                                <thead>
                                    <tr>
                                        <th class="ui-state-default" colspan="3" rowspan="2"></th>
                                        <th class="ui-state-default" colspan="6">Month</th>
                                    </tr>

                                    <tr>
                                        <c:forEach items="#{sfEditManagerBean.labels}" var="lab">
                                            <th class="ui-state-default"><h:outputText value="#{lab}"/></th>
                                        </c:forEach>
                                    </tr>
                                </thead>

                                <tbody class="ui-datatable-data">
                                    <!--                        static part-->
                                    <tr>
                                        <th class="ui-state-default" rowspan="4">Static Method</th>
                                        <th class="ui-state-default">Period</th>
                                        <th class="ui-state-default">
                                            <p:inputText value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedStaticId).staticSF.periodiocity}"
                                                         required="true" requiredMessage="Periodiocity should not be empty."/>
                                        </th>
                                        <c:forEach items="#{sfEditManagerBean.staticPeriods}" var="item">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Level</th>
                                        <c:forEach items="#{sfEditManagerBean.staticPeriods}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.level.get(sfEditManagerBean.selectedStaticId)}">
                                                    <f:convertNumber pattern="#.##"/>
                                                </h:outputText></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Trend</th>
                                        <c:forEach items="#{sfEditManagerBean.staticPeriods}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.trend.get(sfEditManagerBean.selectedStaticId)}">
                                                    <f:convertNumber pattern="#.##"/>
                                                </h:outputText></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Base Projection</th>
                                        <c:forEach items="#{sfEditManagerBean.staticPeriods}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.roundToLong((sfEditManagerBean.trend.get(sfEditManagerBean.selectedStaticId) * item + sfEditManagerBean.level.get(sfEditManagerBean.selectedStaticId))* sfEditManagerBean.returnEstimDesFactorByProductNPeriod(item, sfEditManagerBean.selectedStaticId))}" /></td>
                                        </c:forEach>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <p:commandButton value="Update" ajax="true" update="allProductBPForm, staticForm, staticMsg" action="#{sfEditManagerBean.calculateStatic(sfEditManagerBean.selectedStaticId)}"
                                         oncomplete="handleStaticRequest(xhr, status, args)"/>
                        <p:commandButton value="Cancel" oncomplete="staticDlg.hide()"/>
                        <br/>
                        <br/>
                        <div class="ui-datatable ui-widget">
                            <table border="1" summary="for product a">
                                <caption>
                                    <div class="ui-datatable-header ui-widget-header ui-corner-tl ui-corner-tr">
                                        Static Method Reference Table <h:outputText value="#{sfEditManagerBean.returnProductName(sfEditManagerBean.selectedStaticId)}"/>
                                    </div>
                                </caption>

                                <thead>
                                    <tr>
                                        <th class="ui-state-default" colspan="3"></th>
                                        <c:forEach items="#{sfEditManagerBean.allStaticPeriods}" var="item">
                                            <th class="ui-state-default"><h:outputText value="#{item}"/></th>
                                        </c:forEach>
                                    </tr>
                                </thead>

                                <tbody class="ui-datatable-data">
                                    <!--                        static part-->
                                    <tr>
                                        <th class="ui-state-default" rowspan="8">Static Method</th>
                                        <th class="ui-state-default" colspan="2">Period</th>
                                        <c:forEach items="#{sfEditManagerBean.allStaticPeriods}" var="item">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Act. Demand</th>
                                        <c:forEach items="#{sfEditManagerBean.allActualDemands.get(sfEditManagerBean.selectedStaticId)}" var="item">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default">Des. Demand</th>
                                        <td><h:outputText value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(sfEditManagerBean.selectedStaticId).staticSF.periodiocity}"/></td>
                                        <c:forEach items="#{sfEditManagerBean.allDesDemandFromActual.get(sfEditManagerBean.selectedStaticId)}" var="item">
                                            <td><h:outputText value="#{item}" rendered="#{sfEditManagerBean.renderedDesDFromAcutal(item)}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">P. Des. Demand</th>
                                        <c:forEach items="#{sfEditManagerBean.allDesDemand.get(sfEditManagerBean.selectedStaticId)}" var="item">
                                            <td><h:outputText value="#{item}"/></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Des. Factor</th>
                                        <c:forEach items="#{sfEditManagerBean.allDesFactor.get(sfEditManagerBean.selectedStaticId)}" var="item">
                                            <td><h:outputText value="#{item}">
                                                    <f:convertNumber pattern="#.##"/>
                                                </h:outputText></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Level</th>
                                        <c:forEach items="#{sfEditManagerBean.allStaticPeriods}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.level.get(sfEditManagerBean.selectedStaticId)}">
                                                    <f:convertNumber pattern="#.##"/>
                                                </h:outputText></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Trend</th>
                                        <c:forEach items="#{sfEditManagerBean.allStaticPeriods}" var="item">
                                            <td><h:outputText value="#{sfEditManagerBean.trend.get(sfEditManagerBean.selectedStaticId)}">
                                                    <f:convertNumber pattern="#.##"/>
                                                </h:outputText></td>
                                        </c:forEach>
                                    </tr>

                                    <tr>
                                        <th class="ui-state-default" colspan="2">Ref. Des. Factor</th>
                                        <c:forEach items="#{sfEditManagerBean.allEstimatedDesFactor.get(sfEditManagerBean.selectedStaticId)}" var="item">
                                            <td><h:outputText value="#{item}">
                                                    <f:convertNumber pattern="#.##"/>
                                                </h:outputText></td>
                                        </c:forEach>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <br/>
                        <br/>
                        <p:panel header="Legend">
                            <h:panelGrid columns="8">
                                <h:outputLabel value="Actual Demand"/>
                                <h:outputLabel value="Act. Demand"/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value="Deseasonalized Demand Computed From Actual"/>
                                <h:outputLabel value="Des. Demand"/>
                                <h:outputLabel value=""/>

                                <h:outputLabel value="Deseasonalized Demand Computed From Linear Regression"/>
                                <h:outputLabel value="P. Des. Demand"/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value="Deseasonalized Factor"/>
                                <h:outputLabel value="Des. Factor"/>
                                <h:outputLabel value=""/>

                                <h:outputLabel value="Estimated Deseasonalized Factor For Future Reference"/>
                                <h:outputLabel value="Ref. Des. Factor"/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                                <h:outputLabel value=""/>
                            </h:panelGrid>
                        </p:panel>
                    </h:form>
                </p:dialog>
                <p:dialog id="industryInfoDialog" widgetVar="industryInfoDlg" header="Input Industry Index" showEffect="explode" hideEffect="explode">
                    <h:form>
                        <p:messages id="indInfoMsg" showDetail="true"/>
                        <h:panelGrid columns="2">
                            <h:outputLabel value="Year of Growth"/>
                            <p:inputText required="true" requiredMessage="Yoy should not be empty." value="#{sfEditManagerBean.inputtedIndustryYoY}"/>

                            <h:outputLabel value="Market Share"/>
                            <p:inputText required="true" requiredMessage="Yoy should not be empty." value="#{sfEditManagerBean.inputtedIndustryMarketShare}"/>

                            <c:forEach items="#{sfEditManagerBean.counterForProduct}" var="item">
                                <h:outputText value="Product Share for Product#{item}"/>
                                <p:inputText required="true" requiredMessage="Yoy should not be empty." value="#{sfEditManagerBean.selectedSF.returnProductIndivForecast(item).industrySF.proudctShare}"/>
                            </c:forEach>
                        </h:panelGrid>
                        <p:commandButton value="Update All" ajax="true" update="allProductBPForm, indInfoMsg" actionListener="#{sfEditManagerBean.updateIndustryData}" oncomplete="handleIndustryRequest(xhr, status, args)"/>
                    </h:form>
                </p:dialog>
                <script type="text/javascript">
                    var chartStyle = {
                        padding : 20,
                        border: {color: 0x96acb4, size: 8},
                        legend: {
                            display: "right"
                        }
                    };
                    function handleIndustryRequest(xhr, status, args) {  
                        if(args.validationFailed || !args.isValid) {  
                            jQuery('#industryInfoDialog').parent().effect("shake", { times:3 }, 100);  
                        } else {  
                            industryInfoDlg.hide();  
                        }  
                    }  
                    function handleStaticRequest(xhr, status, args) {  
                        if(args.validationFailed || !args.isValid) {  
                            jQuery('#staticDialog').parent().effect("shake", { times:3 }, 100);  
                        } else {  
                            staticDlg.hide();  
                        }  
                    } 
                    function handleHistoricalRequest(xhr, status, args) {  
                        if(args.validationFailed || !args.isValid) {  
                            jQuery('#historicalDialog').parent().effect("shake", { times:3 }, 100);  
                        } else {  
                            historicalDlg.hide();  
                        }  
                    } 
                </script>
            </p:tab>

            <p:tab title="Reference Figure for all Actual Demands">
                <p:lineChart value="#{sfEditManagerBean.returnActDemandFigure()}"
                             var="sale" xfield="#{sale.month}" style="chartStyle">
                    <p:chartSeries label="Bar A" value="#{sale.salesRevPerMon1}"/>
                    <p:chartSeries label="Bar B" value="#{sale.salesRevPerMon2}"/>
                    <p:chartSeries label="Bar C" value="#{sale.salesRevPerMon3}"/>
                    <p:chartSeries label="Bar D" value="#{sale.salesRevPerMon4}"/>
                </p:lineChart>
            </p:tab>
        </p:tabView>
    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
